package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoManageEditVO;
import com.yunxi.sto.pojo.StoManageVO;
import com.yunxi.sto.pojo.VehicleStockFrozenVO;
import com.yunxi.sto.service.StoManageDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * <p>
 * 仓库结构管理 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-14
 */
@RestController
@RequestMapping("/admin/stoManage")
@Api(tags = "sto:manage", description = "仓库结构管理接口")
public class StoManageController {
 private static final Logger logger = LoggerFactory.getLogger(StoManageController.class);

 @Autowired
 StoManageDubboService stoManageDubboService;

 /*@GetMapping("/page")
 @ApiOperation(value = "查询分页")
 public ApiResult page(StoManageVO stoManageVO, @RequestParam(required = true)Integer pageNum, @RequestParam(required = true)Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoManageDubboService.findPageByVO(stoManageVO,pageNum,pageSize));
 }*/

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 public ApiResult load(StoManageVO stoManageVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoManageDubboService.getById(stoManageVO.getStorageId()));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoManageEditVO stoManageEditVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  return stoManageDubboService.saveOrUpdate(stoManageEditVO);
 }

 @PostMapping("/del")
 @ApiOperation(value = "作废")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id列表") List<String> list,@CurrentUser LoginInfo loginInfo) throws Exception {
  stoManageDubboService.del(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/reset")
 @ApiOperation(value = "恢复")
 public ApiResult reset(@RequestBody @ApiParam(value = "主键id列表") List<String> list,@CurrentUser LoginInfo loginInfo) throws Exception {
  stoManageDubboService.reset(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/frozen")
 @ApiOperation(value = "冻结")
 public ApiResult frozen(@RequestBody @ApiParam(value = "主键id列表") List<VehicleStockFrozenVO> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoManageDubboService.frozen(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/frozenReset")
 @ApiOperation(value = "解冻")
 public ApiResult frozenReset(@RequestBody @ApiParam(value = "主键id列表") List<VehicleStockFrozenVO> list,@CurrentUser LoginInfo loginInfo) throws Exception {
  stoManageDubboService.frozenReset(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @GetMapping("/tree")
 @ApiOperation(value = "仓库树形查询")
 public ApiResult tree(StoManageVO stoManageVO) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  return ResponseUtil.ok(stoManageDubboService.findTreeList());
 }

 @GetMapping("/detail")
 @ApiOperation(value = "通过库道ID获取库位信息")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "storageId", value = "库道ID", required = true, dataType = "String")
 })
 public ApiResult detail(String storageId,Integer pageNum,Integer pageSize) {
  return ResponseUtil.ok(stoManageDubboService.detail(storageId,pageNum,pageSize));
 }

 @GetMapping("/storageList")
 @ApiOperation(value = "仓库列表分页")
 public ApiResult storageList(StoManageVO stoManageVO,@RequestParam(required = true)Integer pageNum, @RequestParam(required = true)Integer pageSize) {
  return ResponseUtil.ok(stoManageDubboService.findPageByVO(stoManageVO,pageNum,pageSize));
 }

 @GetMapping("/areaList")
 @ApiOperation(value = "库区列表")
 public ApiResult areaList(@CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoManageDubboService.areaList());
 }

 @GetMapping("/exportFrozenHis")
 @ApiOperation(value = "导出库位冻结明细")
 public ApiResult exportFrozenHis() throws Exception {
  return ResponseUtil.ok(stoManageDubboService.exportFrozenHis());
 }

}
